﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using RSSReader.MobileClient.ViewModel;

namespace RSSReader.MobileClient
{
    public partial class ArticleDisplayPage : PhoneApplicationPage
    {
        public string _link;
        private ArticleViewModel ArticleVM;

        public ArticleDisplayPage()
        {
            InitializeComponent();
            ArticleVM = new ArticleViewModel();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.ContainsKey("title") && NavigationContext.QueryString.ContainsKey("body") && NavigationContext.QueryString.ContainsKey("link") && NavigationContext.QueryString.ContainsKey("source"))
            {
                ArticleVM.ArticleIsRead(NavigationContext.QueryString["link"], NavigationContext.QueryString["body"], NavigationContext.QueryString["title"], NavigationContext.QueryString["sourceurl"]);
                string _title = NavigationContext.QueryString["title"];
                string _body = NavigationContext.QueryString["body"];
                _link = NavigationContext.QueryString["link"];
                this.ArticleDisplayOnPage.Title.Text = _title;
                this.ArticleDisplayOnPage.Wbrows.NavigateToString("<html><body style='background-color:black; color:white;'><div style='background-color:black; color:white;'>" + _body + "</div></body></html>");
                this.ArticleDisplayOnPage.HyperlinkB.Click += new RoutedEventHandler(HyperlinkB_Click);
            }
        }

        public void HyperlinkB_Click(object sender, RoutedEventArgs e)
        {
            this.ArticleDisplayOnPage.Wbrows.Navigate(new Uri(_link));
            this.ArticleDisplayOnPage.HyperlinkB.Visibility = Visibility.Collapsed;
        }
    }
}